package tcom.huitone.smspfm.interfacz.delrep;

import java.io.IOException;
import java.util.List;

import org.junit.Test;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;

import com.bin.common.utils.StringUtils;
import com.huitone.smspfm.context.utils.ContextUtils;
import com.huitone.smspfm.redis.impl.HashOpts;
import com.huitone.smspfm.redis.impl.ListOpts;
import com.huitone.smspfm.redis.impl.SetOpts;
import com.huitone.smspfm.redis.impl.StringOpts;
import com.huitone.smspfm.redis.impl.ZsetOpts;
import com.huitone.smspfm.redis.pipeline.PipelineOpts;

/**   
* @Title ReadData.java 
* @Package tcom.huitone.smspfm.interfacz.delrep 
* @Description TODO(用一句话描述该文件做什么) 
* @author ybliang   
* @date 2017年4月10日 下午3:59:44 
* @version V1.0   
*/
public class ReadData {
	
	@Test
	public void delete() {
		
		ZsetOpts keyOpts = ContextUtils.getInstance().getBean(ZsetOpts.class);
		
		int innerCode = 0; //
		String errorMsg = null;
		
		Cursor<TypedTuple<String>> cursor1 = keyOpts.scan("ConfigErrorCodeZSet", ScanOptions.scanOptions().match("HTTPResp\\\\u003A105:*:*:cmpp:*").build());
		if (cursor1.hasNext()) { // 针对指定业务端的指定业务类型 HTTPResp\u003A105:屏蔽词:6:cmpp::3253095763DE480493093E9496D2DCA8
			String[] split = StringUtils.toString(cursor1.next().getValue()).split(":");
			innerCode = StringUtils.toInteger(split[2]);
			errorMsg = StringUtils.unEscapeColon(split[1]);
		}
		try {
			cursor1.close();
		} catch (IOException e) {}
		
		System.out.println("innerCode:" + innerCode);
		System.out.println("errorMsg:" + errorMsg);
		
	}

	@Test
	public void read() {
		
		ListOpts listOpts = ContextUtils.getInstance().getBean(ListOpts.class);
		HashOpts hashOpts = ContextUtils.getInstance().getBean(HashOpts.class);
		SetOpts setOpts = ContextUtils.getInstance().getBean(SetOpts.class);
		StringOpts stringOpts = ContextUtils.getInstance().getBean(StringOpts.class);
		
		Cursor<Object> cursor = setOpts.scan("SMNotifyRptSeqSet", ScanOptions.NONE);
		
		int count = 0;
		
		while(cursor.hasNext()) {
			count ++ ;
			System.out.println(cursor.next() + "    " + count);
		}
		
	}
	
	@Test
	public void pipelineTest() {
		
		PipelineOpts pipelineOpts = ContextUtils.getInstance().getBean(PipelineOpts.class);
		
		long startTime = System.currentTimeMillis();
		
		//pipelineOpts.test();
		
		long endTime = System.currentTimeMillis();
		
		System.out.println(endTime - startTime);
		
		ListOpts listOpts = ContextUtils.getInstance().getBean(ListOpts.class);
		
		long startTime2 = System.currentTimeMillis();
		
		for (int i = 0 ; i < 5000 ; i ++) {
			//String string = listOpts.out("SMCache");
		}
		
		long endTime2 = System.currentTimeMillis();
		
		System.out.println(endTime2 - startTime2);
		
	}
}
